*Estimate LQTEs and Y0 using the JTPA training data - Table 1
*Please make sure `ivqte' and `moremata' are installed
cd "C:\Users\Ying Ying Dong"
*Replace `Gender' by male or female
log using ".\Dropbox\Rank Invariance\Empirical application\JTPA\\Results\Table1_Gender.smcl", replace
clear all
set more off
set matsize 5000
version 12

use ".\Dropbox\Rank Invariance\Empirical application\JTPA\JTPA_ContinousAge.dta", clear

global qt "0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85"

gen y=earn
gen z=assignmt
gen t=training
qui sum y
local obs=r(N)
replace hsorged=round(hsorged)
replace married=round(married)
replace wkless13=round(wkless13)

*Table 1: Female
local male=0
**Table 1: Male
*local male=1

*age is in 6 categories, which are represented by 5 age dummies
local cov1 "hsorged  black   hispanic  married  wkless13  age2225 age2629   age3035  age3644   age4554 "
local cov0 "hsorged   black    hispanic   married   wkless13 afdc age2225    age2629    age3035 age3644   age4554 "
qui tostring `cov1', replace
qui tostring `cov0', replace
*sex==1 for male, sex==0 for female	
gen x=hsorged+black+hispanic+married+wkless13+age2225+age2629+age3035+age3644+age4554 if sex==1
replace x=hsorged+black+hispanic+married+wkless13+afdc+age2225+age2629+age3035+age3644+age4554 if sex==0

qui destring x, replace	
qui destring `cov1', replace
qui destring `cov0', replace

if `male'==1 {
keep if sex==1
global cov="`cov1'"
}
else if `male'==0 {
keep if sex==0
global cov="`cov0'"
}

*Estimate LQTE
ivqte y (t=z), quantiles($qt) dummy($cov) variance 
matrix qte=e(b)	
*Estimate Y0
qui replace y=0 if t==1
ivqte y (t=z), quantiles($qt) dummy($cov) 
matrix y0=-1*e(b)
mat l y0
log close
